﻿package com.tudou.skin.common.bar
{
    import com.tudou.skin.common.events.*;
    import com.tudou.utils.*;
    import flash.display.*;
    import flash.events.*;

    public class BarUtil extends Object
    {

        public function BarUtil()
        {
            return;
        }// end function

        public static function actMouse(param1:IBar, param2:Boolean = true, param3:Function = null) : void
        {
            var listener:InteractiveObject;
            var mouseDownHlr:Function;
            var enterFrameHlr:Function;
            var mouseUpHlr:Function;
            var obj:Object;
            var iBar:* = param1;
            var isMouseX:* = param2;
            var lineFun:* = param3;
            mouseDownHlr = function (event:MouseEvent) : void
            {
                var _loc_6:Object = null;
                var _loc_2:* = isMouseX ? (listener.mouseX) : (listener.mouseY);
                var _loc_3:* = iBar.getMin();
                var _loc_4:* = iBar.getMax();
                var _loc_5:* = (_loc_2 - _loc_3) / (_loc_4 - _loc_3);
                if ((_loc_2 - _loc_3) / (_loc_4 - _loc_3) >= 0 && _loc_5 <= 1)
                {
                    _loc_6 = iBar.barData;
                    _loc_6.isDragging = true;
                    listener.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHlr);
                    listener.addEventListener(Event.ENTER_FRAME, enterFrameHlr);
                    listener.dispatchEvent(new BarEvent(BarEvent.START_DRAG, false, true, getValue()));
                }
                return;
            }// end function
            ;
            enterFrameHlr = function (event:Event) : void
            {
                listener.dispatchEvent(new BarEvent(BarEvent.DRAGING, false, true, getValue()));
                return;
            }// end function
            ;
            mouseUpHlr = function (event:MouseEvent) : void
            {
                var _loc_2:* = iBar.barData;
                _loc_2.isDragging = false;
                listener.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHlr);
                listener.removeEventListener(Event.ENTER_FRAME, enterFrameHlr);
                listener.dispatchEvent(new BarEvent(BarEvent.END_DRAG, false, true, getValue()));
                return;
            }// end function
            ;
            var getValue:* = function () : Number
            {
                var _loc_1:Number = 0;
                var _loc_2:* = isMouseX ? (listener.mouseX) : (listener.mouseY);
                var _loc_3:* = iBar.getActMin();
                var _loc_4:* = iBar.getActMax();
                _loc_1 = (_loc_2 - _loc_3) / (_loc_4 - _loc_3);
                _loc_1 = MathUtil.unit(_loc_1);
                var _loc_5:* = iBar.barData.lineFun;
                if (iBar.barData.lineFun != null)
                {
                    _loc_1 = null._loc_5(_loc_1);
                }
                return _loc_1;
            }// end function
            ;
            listener = iBar.getSkin();
            if (listener)
            {
                obj = iBar.barData;
                obj.isMouseX = isMouseX;
                obj.downHlr = mouseDownHlr;
                obj.upHlr = mouseUpHlr;
                obj.enterFrameHlr = enterFrameHlr;
                obj.lineFun = lineFun;
                obj.isDragging = false;
                listener.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHlr);
            }
            return;
        }// end function

        public static function killMouse(param1:IBar) : void
        {
            var _loc_2:* = param1.getSkin();
            var _loc_3:* = param1.barData;
            if (_loc_2)
            {
                if (_loc_3.downHlr)
                {
                    _loc_2.removeEventListener(MouseEvent.MOUSE_DOWN, _loc_3.downHlr);
                }
                if (_loc_3.upHlr)
                {
                    _loc_2.removeEventListener(MouseEvent.MOUSE_UP, _loc_3.upHlr);
                }
                if (_loc_3.enterFrameHlr)
                {
                    _loc_2.removeEventListener(Event.ENTER_FRAME, _loc_3.enterFrameHlr);
                }
                delete _loc_3.isMouseX;
                delete _loc_3.downHlr;
                delete _loc_3.upHlr;
                delete _loc_3.enterFrameHlr;
                delete _loc_3.lineFun;
            }
            return;
        }// end function

    }
}
